# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=guile
pkgname=("$pkgbase" "lib${pkgbase}" "lib${pkgbase}-devel")
pkgver=2.0.11
pkgrel=3
pkgdesc="a portable, embeddable Scheme implementation written in C"
url="http://www.gnu.org/software/guile/"
arch=(i686 x86_64)
license=('GPL')
makedepends=('libltdl' 'gmp-devel' 'ncurses-devel' 'libunistring-devel' 'libgc-devel' 'libffi-devel' 'texinfo')
source=("ftp://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz"
        2.0.9-module-ldflags.patch
        guile-2.0.9-export-symbols.patch
        guile-2.0.9-msys2.patch)
options=('!libtool')
md5sums=('e532c68c6f17822561e3001136635ddd'
         'bf85cd18f7d1c1ab14a02b8eccf6691a'
         '4eb6e6498afe1c704026d499046287ab'
         'ccf1f4a340b21de9f93a5a02a78bf50d')

prepare() {
  cd "${srcdir}/${pkgbase}-${pkgver}"

  patch -p2 -i ${srcdir}/2.0.9-module-ldflags.patch
  patch -p1 -i ${srcdir}/guile-2.0.9-export-symbols.patch
  patch -p1 -i ${srcdir}/guile-2.0.9-msys2.patch

  cp -rf build-aux/snippet ${srcdir}/snippet
  autoreconf -fi
  cp -f ${srcdir}/snippet/* build-aux/snippet/
}

build() {
  cd "${srcdir}/${pkgbase}-${pkgver}"
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --disable-debug-malloc \
    --disable-guile-debug \
    --disable-error-on-warning \
    --disable-rpath \
    --enable-deprecated \
    --enable-networking \
    --enable-nls \
    --enable-posix \
    --enable-regex \
    --with-threads \
    --with-modules \
    --disable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

package_guile() {
  depends=('libguile' 'info')
  install=${pkgbase}.install

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*.dll
  rm -f ${pkgdir}/usr/bin/*-config

  mkdir -p ${pkgdir}/usr/share
  #cp -rf ${srcdir}/dest/usr/share/doc $pkgdir/usr/share/
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/
}

package_libguile() {
  depends=('gmp' 'libltdl' 'ncurses' 'libunistring' 'libgc' 'libffi')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  install -Dm755 ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  install -Dm755 ${srcdir}/dest/usr/lib/*.dll ${pkgdir}/usr/bin/

  #cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/lib/guile ${pkgdir}/usr/lib/
  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share/guile ${pkgdir}/usr/share/
}

package_libguile-devel() {
  depends=("libguile=${pkgver}")
  groups=('development')
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/bin
  install -Dm755 ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib/
  cp -rf ${srcdir}/dest/usr/lib/pkgconfig ${pkgdir}/usr/lib/
  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
}
